package com.xigua.JucOfBeautiful.chapterOne.threadLocal1_11;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/1/2318:46
 */
public class ThreadLocalTest {
    static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    static void print(String str){
        System.out.println(str+":"+threadLocal.get());
        threadLocal.remove();
    }

    public static void main(String[] args) {
        Thread threadOne = new Thread(()->{
            threadLocal.set("threadOne local variable");
            print("threadOne");
            System.out.println("ThreadOne remove after"+" : "+threadLocal.get());
        });

        Thread threadTwo = new Thread(()->{
            threadLocal.set("threadTwo local variable");
            print("threadTwo");
            System.out.println("threadTwo remove after"+" : "+threadLocal.get());
        });

        threadOne.start();
        threadTwo.start();
    }

}
